# -*- coding: utf-8 -*-#
"""
@File : 01_request作业.py.py
@Description :
(问答题)
网址:https://www.ccgp-anhui.gov.cn/site/category?parentId=smNINUwLp%2F04p2g1rUM89Q%3D%3D&childrenCode=anhuiCategory102&utm=site.site-PC-4721.564-pc-websitegroup-nav-front.4.1fff03802d4e11ef96d08f4b994d45f1
接口：https://www.ccgp-anhui.gov.cn/portal/category
发生10页请求获取数据截图打印
@Author : Le.Qing
@Create Time : 2025-04-28 12:45
"""
import json
import requests
import time


class ChromeSimulator:
    def __init__(self):
        self.url = 'https://www.ccgp-anhui.gov.cn/portal/category'
        self.headers = self.get_headers()

    def get_headers(self):
        return {
            'Accept': 'application/json, text/plain, */*',
            'Accept-Encoding': 'gzip, deflate, br, zstd',
            'Accept-Language': 'zh-CN,zh;q=0.9',
            'Cache-Control': 'no-cache',
            'Connection': 'keep-alive',
            'Content-Type': 'application/json;charset=UTF-8',
            'Cookie': 'wzws_sessionid=oGgPBsOANTguNTguNDIuMTYygjQ2NTdiYYEzM2QwZjI=; _zcy_log_client_uuid=ef247a30-23ea-11f0-b0fe-33fb85104146',
            'Host': 'www.ccgp-anhui.gov.cn',
            'Origin': 'https://www.ccgp-anhui.gov.cn',
            'Pragma': 'no-cache',
            'Referer': 'https://www.ccgp-anhui.gov.cn/site/category?parentId=smNINUwLp%2F04p2g1rUM89Q%3D%3D&childrenCode=anhuiCategory102&utm=site.site-PC-4721.564-pc-websitegroup-nav-front.4.1fff03802d4e11ef96d08f4b994d45f1',
            'Sec-Fetch-Dest': 'empty',
            'Sec-Fetch-Mode': 'cors',
            'Sec-Fetch-Site': 'same-origin',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36',
            'X-Requested-With': 'XMLHttpRequest',
            'sec-ch-ua': '"Google Chrome";v="135", "Not-A.Brand";v="8", "Chromium";v="135"',
            'sec-ch-ua-mobile': '?0',
            'sec-ch-ua-platform': '"Windows"'
        }

    def get_page_data(self, pageNo):
        data = {
            "pageNo": pageNo,
            "pageSize": 15,
            "categoryCode": "anhuiCategory102",
            "_t": 1745815300000
        }
        response = requests.post(url=self.url, headers=self.headers, data=json.dumps(data))
        res_dict = response.json()
        page_data = res_dict['result']['data']['data']
        print(f"第{pageNo}页数据为：")
        for index,item in enumerate(page_data):
            print(str(pageNo)+'-'+str(index+1), item['title'])
        print("-"*50)
        time.sleep(1)


cs = ChromeSimulator()

for i in range(15):
    cs.get_page_data(i+1)